﻿using Common.Base;

using GameGraphics.Enums;

namespace GameGraphics.Helper
{
    internal static class ArrowDirectionHelper
    {
        public static ArrowDirectionEnum GetArrowDirection(Position start, Position end)
        {
            if (end.X == start.X && end.Y - 1 == start.Y)
            {
                return ArrowDirectionEnum.Top;
            }

            if (end.X - 1 == start.X && end.Y - 1 == start.Y)
            {
                return ArrowDirectionEnum.TopRight;
            }

            if (end.X + 1 == start.X && end.Y == start.Y)
            {
                return ArrowDirectionEnum.TopLeft;
            }

            if (end.X == start.X && end.Y + 1 == start.Y)
            {
                return ArrowDirectionEnum.Bottom;
            }

            if (end.X - 1 == start.X && end.Y == start.Y)
            {
                return ArrowDirectionEnum.BottomRight;
            }

            return ArrowDirectionEnum.BottomLeft;
        }

        public static Position GetArrowPosition(ArrowDirectionEnum direction, Dimension tileDimension, Size arrowSize)
        {
            int x;
            int y;

            const int YOffset = 8;

            switch (direction)
            {
                case ArrowDirectionEnum.Top:
                    x = tileDimension.X + (tileDimension.Width / 2) - (arrowSize.Width / 2);
                    y = tileDimension.Y - (arrowSize.Height / 2);
                    return new Position(x, y);

                case ArrowDirectionEnum.TopLeft:
                    x = tileDimension.X + (tileDimension.Width / 6) - (arrowSize.Width / 2);
                    y = tileDimension.Y + ((tileDimension.Height - YOffset) / 4) - (arrowSize.Height / 2);
                    return new Position(x, y);

                case ArrowDirectionEnum.TopRight:
                    x = tileDimension.X + tileDimension.Width - (tileDimension.Width / 6) - (arrowSize.Width / 2);
                    y = tileDimension.Y + ((tileDimension.Height - YOffset) / 4) - (arrowSize.Height / 2);
                    return new Position(x, y);

                case ArrowDirectionEnum.Bottom:
                    x = tileDimension.X + (tileDimension.Width / 2) - (arrowSize.Width / 2);
                    y = tileDimension.Y + (tileDimension.Height - YOffset) - (arrowSize.Height / 2);
                    return new Position(x, y);

                case ArrowDirectionEnum.BottomLeft:
                    x = tileDimension.X + (tileDimension.Width / 6) - (arrowSize.Width / 2);
                    y = tileDimension.Y + (tileDimension.Height - YOffset) - ((tileDimension.Height - YOffset) / 4) - (arrowSize.Height / 2);
                    return new Position(x, y);

                case ArrowDirectionEnum.BottomRight:
                    x = tileDimension.X + tileDimension.Width - (tileDimension.Width / 6) - (arrowSize.Width / 2);
                    y = tileDimension.Y + (tileDimension.Height - YOffset) - ((tileDimension.Height - YOffset) / 4) - (arrowSize.Height / 2);
                    return new Position(x, y);
            }

            return new Position(0, 0);
        }
    }
}